#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
#include <vector>
#include <stack>
#include <queue>
#include <set>
using namespace std;
int calD(int a, int b)
{
    if (a > b)
        return a - b;
    else
        return b - a;
}
int minDis(vector<int> &A, vector<int> &B, vector<int> &C)
{
    int MinDis = INT32_MAX, i = 0, j = 0, k = 0;
    for (int a = A[i], b = B[j], c = C[k]; i < A.size() && j < B.size() && k < C.size();)
    {
        a = A[i], b = B[j], c = C[k];
        MinDis = min(MinDis, calD(a, b) + calD(a, c) + calD(b, c));
        if (a < b && a < c)
            i++;
        else if (b < a && b < c)
            j++;
        else if (c < a && c < b)
            k++;
        else
            break;
    }
    return MinDis;
}
int main()
{
    vector<int> A = {-1, 0, 9}, B = {-25, 10, 10, 11}, C = {2, 9, 17, 30, 41};
    printf("MinDis = %d\n", minDis(A, B, C));
}